//---------------------------------------------------------------------------
// Name:	utils.h
// Desc:	Source of utils
// Author:	D.C
// Date:	2007-1-30
//---------------------------------------------------------------------------
#include <hal.h>
#include "utils.h"

TInt GetNumLen(TInt aVal)
{
	TInt i=0;
	if (0==aVal)
		return 0;
	if (aVal<0)
	{
		++i;
		aVal=Abs(aVal);
	}
	while(aVal>0)
	{
		++i;
		aVal/=10;
	};
	return i;
}
#include <eikenv.h>
#include <APGCLI.H>
#include <APGTASK.H>
void OpenUrl(const TDesC& aUrl)
{
	if(0==aUrl.Length())
		return;
	const TInt KBrowserUid1=0x1020724D;
	const TInt KBrowserUid2=0x10008D39;
	TUid browserId(TUid::Uid(KBrowserUid1));
	
	_LIT(URL_PRAM,"4 %S");
	HBufC* param = HBufC::New(aUrl.Length()+URL_PRAM().Length());
	param->Des().Format(URL_PRAM,&aUrl);
	
	RApaLsSession appArcSession;
	appArcSession.Connect();
	
	TApaAppInfo appInfo;
	if (appArcSession.GetAppInfo(appInfo,browserId)!=KErrNone)
	{
		browserId = TUid::Uid(KBrowserUid2);
	}

	TApaTaskList taskList(CEikonEnv::Static()->WsSession());
	TApaTask task = taskList.FindApp(browserId);
	if (task.Exists())
	{
		HBufC8* param8 = HBufC8::New(param->Length()*4);
		param8->Des().Append(*param);
		task.SendMessage(TUid::Uid(0),*param8);
		SAFE_DELETE(param8);
	}
	else
	{
		TThreadId id;
		appArcSession.StartDocument(*param,browserId,id);
	}
	appArcSession.Close();
	SAFE_DELETE(param);
}
HBufC* StringOddEvenSwap(const TDesC& aString)
{
	TInt aCount=aString.Length();
	if(0==aCount)
		return 0;
	HBufC* aNew=HBufC::New(aString.Length());
	TPtr aNewPtr(aNew->Des());
	TInt i=1;
	for(;i<aCount;i+=2)
	{
		aNewPtr.Append(&aString.operator [](i),1);
		aNewPtr.Append(&aString.operator [](i-1),1);
	}
	if(i%2&&i<=aCount)
	{
		aNewPtr.Append(&aString.operator [](i-1),1);
	}
	return aNew;
}
static TInt g_qwert_id[13]=
{
	0x20001858,//Nokia E61
	0x20002D7F,//Nokia E61i
	0x20001859,//Nokia E62
	0x2000249B,//Nokia E71
	0x200025C3,//Nokia E63
	0x20014DD8,//Nokia E71x
	0x20014DD0,//Nokia E72
	0x20029A6D,//Nokia E73 mode
	0x20024101,//Nokia X5-01
	0x20024100,//Nokia E5-00
	0x200227E2,//Nokia 6760 slide
	0x200227E3,//Nokia 6790 slide
	0x2001DE98 //Nokia 6790 surge
};
TBool IsQwertAnd3rd()
{
	TInt aID;
	HAL::Get(HALData::EMachineUid,aID);
	return (aID==g_qwert_id[0] || 
			aID==g_qwert_id[1] || 
			aID==g_qwert_id[2] || 
			aID==g_qwert_id[3] || 
			aID==g_qwert_id[4] || 
			aID==g_qwert_id[5] || 
			aID==g_qwert_id[6] || 
			aID==g_qwert_id[7] || 
			aID==g_qwert_id[8] || 
			aID==g_qwert_id[9] || 
			aID==g_qwert_id[10] || 
			aID==g_qwert_id[11] || 
			aID==g_qwert_id[12] || 
			aID==g_qwert_id[13]);
}
